<!--
 * @Description: 绝对定位
 * @Author: rendc
 * @Date: 2025-09-16 11:29:26
 * @LastEditors: rendc
 * @LastEditTime: 2025-09-16 14:29:12
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>绝对定位</title>
  <style>
    body {
      margin: 0;
    }

    #app {
      border: 1px solid red;
      /* 相对定位 */
      position: relative;
      left: 0px;
      height: 600px;
    }

    .div0 {
      border: 1px solid red;
      display: inline-block;
      width: 50%;
      height: 300px;
    }

    .right {
      /* 绝对定位 相对与body的位置 */
      position: absolute;
      left: 0%;
      /* right: 0; */
      /* bottom: 0; */
      /* right: calc(-50% - 1px); */
      /* top: -302px; */
    }

    .app1 {
      border: 1px solid red;
      /* 相对定位 */
      position: relative;
    }

    .div1,
    .div1-1,
    .div1-1-1 {
      display: inline-block;
    }

    .div1 {
      border: 1px solid red;
      width: 500px;
      height: 500px;
    }

    .div1-1 {
      border: 1px solid skyblue;
      width: 300px;
      height: 300px;
      /* 相对定位 */
      position: relative;
    }

    .div1-1-1 {
      border: 1px solid hotpink;
      width: 150px;
      height: 150px;
      /* 绝对定位 */
      position: absolute;
      left: 50%;
      margin-left: -75px;
      top: 50%;
      margin-top: -75px;
      /* top: 150px; */
    }
  </style>
</head>

<body>
  <div id="app" class="">
    <div class="div0">左</div>
    <div class="right div0">右 - 绝对定位</div>
    <div class="div0">下边的兄弟元素</div>
  </div>
  <div class="app1">
    <div class="div1">
      <div class="div1-1">
        <div class="div1-1-1">
          div1-1-1
        </div>
      </div>
    </div>
    <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</body>

</html>